package project.ia04.agents.gui;

import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import project.ia04.utils.Data;

public class XAgentGetHistorical extends Behaviour {
	
	private int state = 0;

	@Override
	public void action() {
		switch(state){
		case 0:
			System.out.println("XAgentGetHistorical --> Send2StudioAgent");
			ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
			message.setConversationId(Data.GETHISTORICAL);
			message.addReceiver(((XAgent)myAgent).getEnvAgent());
			myAgent.send(message);
			state++;
			break;
		case 1:
			MessageTemplate template = MessageTemplate.and(MessageTemplate.MatchPerformative(ACLMessage.INFORM),
					MessageTemplate.MatchConversationId(Data.GETHISTORICAL));
			message = myAgent.receive(template);
			if(message != null){
				System.out.println("XAgentGetHistorical --> ReceiveFromStudioAgent");
				((XAgent)myAgent).send2Frame(Data.GETHISTORICAL,message.getContent());
				state++;
			}
			else
				block();
			break;
		}
	}

	@Override
	public boolean done() {
		// TODO Auto-generated method stub
		return state == 2;
	}

}
